#!/usr/bin/env sh
echo Hello from the baseline server profile 182-pre-setup.sh.pre hook!
echo "====> USER_BASE_DN=[${USER_BASE_DN}]"
computedDomain=$(echo ${USER_BASE_DN} | sed 's/^dc=\([^,]*\).*/\1/' )
computedOrg=$(echo ${USER_BASE_DN} | sed 's/^o=\([^,]*\).*/\1/' )

if ! test "${USER_BASE_DN}" = "${computedDomain}"; then
    cat<<END_DOMAIN >> "${CONTAINER_ENV}"
BASE_VALUE=${computedDomain}
BASE_ATTRIBUTE=dc
BASE_CLASS=domain
END_DOMAIN

elif ! test "${USER_BASE_DN}" = "${computedOrg}"; then
    cat<<END_ORG >> "${CONTAINER_ENV}"
BASE_VALUE=${computedOrg}
BASE_ATTRIBUTE=o
BASE_CLASS=organization
END_ORG

else
    echo_red "ERROR: the base is expected to be dc=<your domain> or o=<your org>"
    exit 183
fi
